<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/commons/inc.jsp" %>

<h3 id="navTitleId">体质调查</h3>

<script>
function show(){
	var a = '<s:property value='physicalResult.answer'/>';
	if(a!=null){
		a = a.split(",");
		for(var i=1;i<=a.length;i++){
			$('answer'+i+"-"+a[i-1].trim()).checked = true;
		}
	}
}
</script>
<body id="body">

<%@include file="/commons/showmessage.jsp" %>

<form name="physicalform" id="physicalform" method="post" action="${contextPath}/survey/survey.action?method=saveEditPhysicalSurvey">
	<s:hidden name="physicalResult.seqid" id="physicalResult.seqid"></s:hidden>
	<s:hidden name="physicalResult.patientid" id="physicalResult.patientid"></s:hidden>
	<s:hidden name="result" id="result"></s:hidden>
	<s:hidden name="answer" id="answer"></s:hidden>
	<s:hidden name="patientid" id="patientid"></s:hidden>
	
	<table border="0" cellspacing="1" cellpadding="0" class="formTable" width="100%" >
		<thead>
			<tr><td width="100%" align="left" class="form-th" colspan="7">请根据近一年的体验和感觉，回答以下问题。</td></tr>
			<tr><td width="100%" align="left" class="form-th" colspan="7">中医体质分类调查表</td></tr>
		</thead>
		 
		<tbody> 
		  <s:iterator value="physicalSurvey" id="ind" status="st">	 
		  	<tr>
		  		<td align="center" class="form-td">${category}.${number}</td>
				<td align="left" class="form-td">
				<s:if test="category.startsWith('F') && number==7">
					<s:if test="gender!=null && gender==1">您的阴囊潮湿出汗吗?（限男性回答）</s:if>
					<s:else>您带下色黄(白带颜色发黄)吗?（限女性回答）</s:else>
				</s:if>
				<s:else>${question}</s:else></td>
				<s:if test="category.startsWith('A') && (number==2 || number==3 || number==6)">
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-5" value="5"/><font style="vertical-align:sub;">没有（或不）</font></td>
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-4" value="4"/><font style="vertical-align:sub;">很少</font></td>
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-3" value="3"/><font style="vertical-align:sub;">有时</font></td>	
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-2" value="2"/><font style="vertical-align:sub;">经常</font></td>	
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-1" value="1"/><font style="vertical-align:sub;">总是</font></td>
				</s:if>
				<s:else>
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-1" value="1"/><font style="vertical-align:sub;">没有（或不）</font></td>
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-2" value="2"/><font style="vertical-align:sub;">很少</font></td>
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-3" value="3"/><font style="vertical-align:sub;">有时</font></td>	
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-4" value="4"/><font style="vertical-align:sub;">经常</font></td>	
					<td align="left" class="form-td"><input style="vertical-align:sub;" type="radio" name="answer${st.index+1}" id="answer${st.index+1}-5" value="5"/><font style="vertical-align:sub;">总是</font></td>	
				</s:else>
			</tr>
	 	</s:iterator>
	 		<script>show()</script>
	 		<tr>
	 			<td align="center" class="form-td"><b>体质：</b></td>
	 			<td align="left" class="form-td" colspan="6"><s:property value='physicalResult.result'/></td>
	 		</tr>
		</tbody>
	</table>	  
	<table>
		<tr>
			<td align="center" colspan="5">
			 <input type="reset" value="重置">
		    <input type="button" onclick="saveEdit();" value="保存"></td>
		</tr>
	</table>
</form>

<%@include file="/commons/tableSel.jsp" %>

</body>

<style type="text/css">
body {
	height: 100%;
	width: 100%;
}
</style>

<script>
function saveEdit(){
	if(!Validator.Validate($('physicalform'),3)){
		return;
	}	

	var s = "";
	var result="";
	var z = new Array(0,0,0,0,0,0,0,0,0);
	var t = new Array('平和质','气虚质','阳虚质','阴虚质','痰湿质','湿热质','血瘀质','气郁质','特禀质');
	
	<s:iterator value="physicalSurvey" id="ind" status="st">
		var category = '<s:property value='#ind.category'/>';
		var number = '<s:property value='#ind.number'/>';
		var i = '<s:property value='#st.index+1'/>';
		var r = document.getElementsByName("answer"+i);
		if(r!=null){
			var flag = false;
		 	for(var j=0;j<r.length;j++){
		 		if(r[j].checked){
					s += r[j].value+",";
					if(category=='A'){
						z[0] += parseInt(r[j].value);
					}else if(category=='B'){
						z[1] += parseInt(r[j].value);
					}else if(category=='C'){
						z[2] += parseInt(r[j].value);
					}else if(category=='D'){
						z[3] += parseInt(r[j].value);
					}else if(category=='E'){
						z[4] += parseInt(r[j].value);
					}else if(category=='F'){
						z[5] += parseInt(r[j].value);
					}else if(category=='G'){
						z[6] += parseInt(r[j].value);
					}else if(category=='H'){
						z[7] += parseInt(r[j].value);
					}else if(category=='I'){
						z[8] += parseInt(r[j].value);
					}
					flag = true;
				}
		 	}
		 	if(!flag){
			 	alert("请填写完整: 第"+category+"."+number+"题");
			 	return;
		 	}
		}
	</s:iterator>
	
	z[0] = Math.round((z[0]-7)/28*100);
	z[1] = Math.round((z[1]-6)/24*100);
	z[2] = Math.round((z[2]-6)/24*100);
	z[3] = Math.round((z[3]-7)/28*100);
	z[4] = Math.round((z[4]-8)/32*100);
	z[5] = Math.round((z[5]-7)/28*100);
	z[6] = Math.round((z[6]-7)/28*100);
	z[7] = Math.round((z[7]-7)/28*100);
	z[8] = Math.round((z[8]-7)/28*100);

	var f1=0, f2=0;
	for(var i=1;i<z.length;i++){
		if(z[i]>=40){
			result += t[i]+";";
			f1 = 1;
		}else if(z[i]>=30){
			result += "有"+ t[i]+"倾向;";
			f2 = 1;
		}
	}
	if(z[0]>=60){
		if(f1==0 && f2==0){
			result = t[0]+","+ result;
		}else if(f1==0 && f2==1){
			result = "基本是" + t[0]+ "," + result;
		}
	}
	if(s!=""){
		s = s.substring(0,s.length-1);
	}
	$('physicalform').answer.value = s;
	if(result==""){
		$('physicalform').result.value = "无明确体质";
	}else{
		$('physicalform').result.value = result;
	}
	$('physicalform').submit();
}
 
</script>